import { useRefModel } from "@/utils/hooks";

export default defineComponent({
  name: "SDatePicker",
  props: {
    modelValue: {
      type: String,
      default: undefined,
    },
    allowClear: {
      type: Boolean,
      default: true,
    },
    showTime: {
      type: Boolean,
      default: false,
    },
    placeholder: {
      type: String,
      default: $t("placeholder75"),
    },
    format: {
      type: [String, Function],
      default: () => (value) =>
        getTimeByZone(value.format("YYYY-MM-DD HH:mm:ss")),
    },
  },
  emits: ["update:modelValue"],
  setup(props, { expose, emit, slots, attrs }: any) {
    const tmp_props = reactive<any>({});
    Object.keys(props).forEach((key: any) => {
      tmp_props[key] = props[key]?.value ?? props[key];
    });
    const keyword = useRefModel(props, "modelValue", emit);
    const tmp_attrs = reactive<any>({});
    Object.keys(attrs).forEach((key: any) => {
      tmp_attrs[key] = attrs[key]?.value ?? attrs[key];
    });

    const $props = {
      ...lodash.omit(tmp_props, ["modelValue"]),
      ...tmp_attrs,
    };
    return () => (
      <a-date-picker vModel:value={keyword.value} vSlots={slots} {...$props} />
    );
  },
});
